package com.wf.day_0604.test2;

import java.util.Arrays;
import java.util.function.Consumer;

/**
 * @author mpk
 * @since 2024/6/4 15:59:35
 */

/*/格式化打印信息  String[] array = { "张三,女", "李四,女", "王二麻,男" };
        如上字符串数组当中存有多条信息，请按照格式姓名：XX。性别：XX。的格式将信息打印出来。
        要求将打印姓名的动作作为第一个Consumer接口的Lambda实例，将打印性别的动作作为第二个Consumer接口的Lambda实例。*/
public class ConsumerDemo {
    public static void main(String[] args) {

        String[] array = {"张三,女", "李四,女", "王二麻,男"};
        for (String string : array) {
            printInfo(
                    s -> {
                        String[] split = s.split(",");
                        System.out.print("姓名：" + split[0] + " ");

                    },
                    s -> {
                        String[] split = s.split(",");
                        System.out.println("年龄：" + split[1]);
                    },
                    string
            );
        }
    }

    private static void printInfo(Consumer<String> name, Consumer<String> sex, String s) {


        name.andThen(sex).accept(s);


    }
}


           /*    for (int i = 0; i <3 ; i++) {
            int finalI = i;
            printInfo(s->{
                String[] split = s[finalI].split(",");
                System.out.print("姓名："+split[0]+" ");

            }, s->{
                String[] split = s[finalI].split(",");
                System.out.println("年龄："+split[1]);
            } );
        }


    }

    private static void printInfo(Consumer<String[]> name,Consumer<String[]> sex) {

        String[] array = { "张三,女", "李四,女", "王二麻,男" };
        name.andThen(sex).accept(array);

    }*/




